<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
<?=$page_title?>
</title>
<base href="<?=base_url()?>" />
<script type="text/javascript" src="js/jquery.js"></script>
<!--time-->
<link rel="stylesheet" href="themes/base/jquery.ui.all.css">
<script src="js/ui/jquery.ui.core.js"></script>
<script src="js/ui/jquery.ui.widget.js"></script>
<script src="js/ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="css/demos.css">
<!--弹窗-->
<link href="css/clientpublic.css" rel="stylesheet" type="text/css">
<link href="css/esui.css" rel="stylesheet" type="text/css">
<link href="css/initaccount.css" rel="stylesheet" type="text/css">
<link href="css/guo.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="js/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="js/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="js/fancybox/jquery.fancybox-1.3.4.css" />
<link rel="stylesheet" type="text/css" href="css/jia.css" />
<!--提示-->
<script language='javascript' src='js/suggest.js'></script>
<link href="js/suggest.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	$(document).ready(function() {
		jQuery.ajaxSetup ({cache:false}); /*让ajax不调用浏览的缓存*/
		$(".various1").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'hideOnOverlayClick' : false,
		'onComplete'	: function() {
				var suggest = new GoogleSuggest("myform", "customer_name", 0,'');
			}
		});

		$(".g_title_sub").click(function(){
            var subject=$.trim($("#name").val());
            if(subject == ""){
              alert("请输入名称后查询");
              $("#name").focus();
            }else{
				location.href="<?=base_url()?>index.php/opportunity/check/"+subject+"";
              }
		})

		$("#check_info").change(function(){
			var user_id = $("#check_info").val();
			location.href="<?= base_url()?>index.php/opportunity/check_user_messages/"+user_id+"";
		})
	});
</script>

</head>
<body>
	<div id="Holder">
		<div id="MainPage">
			<!--头部-->
			<?php include('top.php')?>

			<div id="Subnav">
				<ul>
					<li class="active show"></li>
				</ul>
			</div>
			<!--中间部分-->
			<div id="MainBody">
				<div class="g_title">
					<div class="g_earch">
						<input type="text" class="g_title_text"
							value="销售机会名称" onClick="this.value=''" id="name"><input
							type="button" value=" " class="g_title_sub">
					</div>
                    <div class="g_select">
                    	<?php
                       		$user_name = $this->session->userdata('username');
                       		$role = $this->session->userdata('role');
                       		?>
                       		<?php if($role == '经理' || $role == '商务助理'):?>
                    	<select id="check_info">
                    	<option value="0" <?php if($check_user_name == ''):?> selected='selected' <?php endif;?>>请选择所有者</option>
                    	<?php foreach ($all_users as $user):?>
                    	    	<?php if($user->user_name != '何俊斌'):?>
                    			<option value="<?= $user->id?>" <?php if($user->user_name == $check_user_name):?> selected='selected' <?php endif;?>><?= $user->user_name?></option>
                    		<?php endif;?>
                        <?php endforeach;?>
                        </select>
                        <?php endif;?>
                    </div>
					<div class="add_customer">
						<div class="add_customer_bg3"><?=anchor('opportunity/show_contacter_add/',' ','class="various1"','id="find"') ?></div>
					</div>
				</div>
				<table id="ContentTable" class="data-box">
					<thead>
						<tr class="border-in">
							<th><div>ID</div></th>
							<th><div>机会主题</div></th>
							<th><div>客户</div></th>
							<th><div>负责人</div></th>
							<th><div>预计签订日期</div></th>
							<th><div>预期金额(万元)</div></th>
							<th><div>可能性(%)</div></th>
							<th><div>阶段</div></th>
							<th><div>状态</div></th>
                            <th><div>编辑</div></th>
						</tr>
					</thead>
					<tbody>
					<?php foreach ($sales as $sales_item): ?>
					<tr class="data-box-row">
							<td><?=$sales_item->opportunity_id ?></td>
							<td><?=$sales_item->subject ?></td>
							<td><?=$sales_item->customer_name ?></td>
							<td><?=$sales_item->principal ?></td>
							<?php
							if($sales_item->expected_signing_date == null || $sales_item->expected_signing_date == '' || $sales_item->expected_signing_date == '0000-00-00 00:00:00'){
								$expectedsigningdate = '';
							}else{
								$datatime = strtotime($sales_item->expected_signing_date);
								$expectedsigningdate = date( "Y-m-d",$datatime);
							}
							?>
							<td><?= $expectedsigningdate ?></td>
							<td> <?php if($sales_item->expected_amount): ?> <?= $sales_item->expected_amount ?> <?php endif;?></td>
							<td><?= $sales_item->possibility ?></td>
							<td><?= $sales_item->stage ?></td>
                            <td><?= $sales_item->status ?></td>
							<td><a href="<?=base_url()?>index.php/opportunity/find/<?=$sales_item->id ?>"
								class="various1 g_see" id="find" title="">查看</a>&nbsp;&nbsp; <a
								href="<?=base_url()?>index.php/opportunity/edit/<?=$sales_item->id ?>"
								class="various1 g_edit" id="find" title="">编辑</a>&nbsp;&nbsp; <span class="g_dele"
								id="delete<?=$sales_item->id ?>">删除</span> <input
								type="hidden" id="sales_id<?=$sales_item->id ?>"
								value="<?=$sales_item->id ?>" /> <script
									type="text/javascript">
                                     $(function(){
                                    	 $("#delete<?=$sales_item->id ?>").click(function(){
                                  			if (window.confirm("您确定要删除吗？")) {
                                  				var id=$("#sales_id<?=$sales_item->id ?>").val();
                                  				location.href="<?=base_url()?>index.php/opportunity/delete/"+id+"";
                                  			} else {
                                  			}
                                  		})
                                     })
								</script></td>
						</tr>
		          <?php endforeach; ?>
		        </tbody>
				</table>
				<div id="PageControl">
					<div class="page-control">
						<div class="border-in">
							<span class="perpage"> <span class="perpage-text">
							  <?php if($pag_links){?>
								<?echo ($offset) ? ($offset+1):1;?> - <?=$current_total?> 条（共<?=$total?>条）
							<?php }?>
							</span>
							</span>
							<p>
								<?php if($pag_links){
							    	echo $pag_links;
							    }?>
							</p>
						</div>
					</div>
				</div>
			</div>
			<!--结尾-->
			<?php include('footer.php')?>
		</div>
	</div>
	<input type="hidden" id="baseurl" value="<?=base_url()?>"/>
</body>
</html>
	<script>
	$(function() {
		$( "#datepicker" ).datepicker();
		$("table").delegate('tr',"hover", function(){
			$(this).toggleClass("hover");
		});
	});
	</script>

	<?=$error_info?>




